package com.ljm.controller;/**
 * @author： li
 * @date： 2021-05-18 19:23
 * @version 1.0
 */

import com.ljm.bin.wxuser;
import com.ljm.service.userService;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author： Administrator
 * @date： 2021-05-18 19:23
 * @version 1.0
 */
@WebServlet("/register")
public class registerServlet implements Servlet {
    @Override
    public void init(ServletConfig config) throws ServletException {

    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        res.setContentType("text/json; charset=utf-8");
        PrintWriter out =res.getWriter();
        JSONArray ja = new JSONArray();
        JSONObject jo = new JSONObject();
        String username=req.getParameter("username");
        String password=req.getParameter("password");
        wxuser us=new wxuser();
        us.setUsername(username);
        us.setPassword(password);
        userService userservice=new userService();
        int i=0;
        i=userservice.register(us);
        jo.put("flag",i);
        ja.add(jo);
        out.println(ja);
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
